//
//  MBMessageTableViewCell.m
//  MemberBusiness-ios
//
//  Created by cherry pu on 2018/4/23.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBMessageTableViewCell.h"

@interface MBMessageTableViewCell ()
@property (nonatomic,weak)UILabel* timeLabel;
@property (nonatomic,weak)UILabel* subLabel;
@end

@implementation MBMessageTableViewCell
@dynamic viewModel;

-(void)setupLayout
{
    [super setupLayout];
    
    self.contentView.backgroundColor = COLOR_BG;
    
    UIImageView* bgImageView = [[UIImageView alloc]initWithImage:[UIImage imageFromColor:[UIColor whiteColor] forSize:CGSizeMake(SCREEN_WIDTH-[UIView lf_sizeFromIphone6:24], [UIView lf_sizeFromIphone6:93]) withCornerRadius:[UIView lf_sizeFromIphone6:6]]];
    [self.contentView addSubview:bgImageView];
    
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake([UIView lf_sizeFromIphone6:12], [UIView lf_sizeFromIphone6:12], 0, [UIView lf_sizeFromIphone6:12]));
    }];

    UILabel* timeLabel = [[UILabel alloc]init];
    self.timeLabel = timeLabel;
    timeLabel.text = @"2017-12-14";
    timeLabel.font = [UIFont lf_systemFontOfSize:12];
    timeLabel.textColor = [UIColor colorWithR:152 G:152 B:152];
    [bgImageView addSubview:timeLabel];
    
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgImageView).offset([UIView lf_sizeFromIphone6:16]);
        make.centerX.equalTo(bgImageView);
    }];
    
    UILabel* titleLabel = [[UILabel alloc]init];
    titleLabel.text = @"消息通知";
    titleLabel.font = [UIFont lf_systemFontOfSize:14];
    titleLabel.textColor = [UIColor colorWithR:40 G:40 B:40];
    [bgImageView addSubview:titleLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgImageView).offset([UIView lf_sizeFromIphone6:12]);
        make.top.equalTo(timeLabel.mas_bottom).offset([UIView lf_sizeFromIphone6:15]);
    }];
    
    UIImageView* iconImageView = [[UIImageView alloc]initWithImage:[UIImage imageFromColor:COLOR_MAIN forSize:CGSizeMake([UIView lf_sizeFromIphone6:8], [UIView lf_sizeFromIphone6:8]) withCornerRadius:[UIView lf_sizeFromIphone6:4]]];
    [bgImageView addSubview:iconImageView];
    
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.top.equalTo(titleLabel.mas_bottom).offset([UIView lf_sizeFromIphone6:14]);
    }];
    
    UILabel* subLabel = [[UILabel alloc]init];
    self.subLabel = subLabel;
    subLabel.text = @"亲爱的安迪2017，您的订单已发货";
    subLabel.numberOfLines = 0;
    subLabel.font = [UIFont lf_systemFontOfSize:13];
    subLabel.textColor = [UIColor colorWithR:120 G:120 B:120];
    [bgImageView addSubview:subLabel];
    
    [subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(iconImageView).offset([UIView lf_sizeFromIphone6:-5]);
        make.left.equalTo(iconImageView.mas_right).offset([UIView lf_sizeFromIphone6:7]);
        make.right.equalTo(bgImageView).offset([UIView lf_sizeFromIphone6:-12]);
    }];
}

-(void)setupData
{
    [super setupData];
    
    self.timeLabel.text = self.viewModel.dataModel.create_time;
    self.subLabel.text = self.viewModel.dataModel.content;
}

+(NSNumber *)calculateRowHeightWithViewModel:(MBMessageTableCellViewModel *)viewModel
{
    return [viewModel cacheCellHeightWithCalculateBlock:^NSNumber * _Nonnull{
        return viewModel.totalHeight;
    }];
}

@end
